#include "Student.h"

int Student::getType()
{
	return STUDENT;
}

Student::Student(const Student& src) : People(src.name, src.birthday, src.id)
{
	setGrade(src.grade);
	setNumberOfProject(src.no_project);
	this->score = 0;
	setScore(src.score, src.no_project);
}

Student::Student(char* name, Date birthday, int id, int grade, int no_project, float* score) : People(name, birthday, id)
{
	setGrade(grade);
	setNumberOfProject(no_project);
	this->score = 0;
	setScore(score, no_project);
}

void Student::PrintInfo()
{
	People::PrintInfo();
	cout << "Grade: " << grade << endl;
	cout << "Number of project(s): " << no_project << endl;
	cout << "Average Score: " << averageScore() << endl;
}

void Student::PrintInfo(ostream &out)
{
	People::PrintInfo(out);
	out << "Grade: " << grade << endl;
	out << "Number of project(s): " << no_project << endl;
	out << "Average Score: " << averageScore() << endl;
}
int Student::getGrade()
{
	return grade;
}
int Student::getNumberOfProject()
{
	return no_project;
}
float* Student::getScore()
{
	float* res = new float[no_project];
	memcpy(res, score, no_project * sizeof(float));
	return res;
}
void Student::setGrade(int grade)
{
	this->grade = grade;
}
void Student::setNumberOfProject(int no_project)
{
	this->no_project = no_project;
}
void Student::setScore(float* score, int n)
{
	if (!score)
		return;
	if (this->score == 0)
		delete[] this->score;
	this->score = new float[n];
	memcpy(this->score, score, n * sizeof(float));
}
float Student::getAverageScore()
{
	return averageScore();
}
float Student::averageScore()
{
	if (!score)
		return 0;
	float res = 0;
	for (int i = 0; i < no_project; ++i)
		res += score[i];
	return res / no_project;
}

void* Student::Clone()
{
	return new Student(*this);
}

Student::~Student()
{
	delete[] score;
}

